<?php
	require_once( "inc_systemFunctions.php" );
	page_header( "Wayne Schlegel Inc. | Setup", true, "myflight" );
	
	include( "_setup_adminNavi.php" );
?>

<?php
if( !empty( $_POST['send'] ) && $_POST['send']=="SAVE" ){
	if( empty( $_POST['isActive'] ) ) {
		$_POST['isActive'] = 0;
	}
	$sql = "INSERT INTO product ( internalName, marketingName, itemNumber, quickAccessCode, productImages_id, isActive, productCategory_id,  lastWriteAccess, tbl_shelfs_id, slotInShelf, googleReviewSearchString ) VALUES ('" . $_POST['internalName'] . "', '" . $_POST['marketingName'] . "', '" . $_POST['itemNumber'] . "', '" . $_POST['shortCode'] . "', '" . $_POST['image'] . "', '" . $_POST['isActive'] . "', '" . $_POST['productCategory'] . "', '" . strftime("%Y-%m-%d %H:%M:%S", time() ) . "', '" . $_POST['productCategory'] . "', '" . $_POST['slotInShelf'] . "', '" . $_POST['googleReviewSearchString'] . "')";
	$res = mysql_query( $sql );
	if( $res ) {
		$lastId = mysql_insert_id();
		echo "<p><strong>" . $_POST['marketingName'] . "</strong> added with the following ID: " . $lastId . "</p>";
	} else {
		echo "<p><strong>" . $_POST['marketingName'] . "</strong> NOT added!</p>" . mysql_error();
	}
}

?>

<h1>add product</h1>
<form class="adminForm" method="post" action="" class="admin">
	<?php makeFormField( "text"    , "internalName" , "product name (internal)" )?>
	<?php makeFormField( "text"    , "marketingName", "product name" )?>
	<?php makeFormField( "text"    , "itemNumber"   , "item number" )?>
	<?php makeFormField( "text"    , "shortCode"    , "code for quick access" )?>

	<label for="productCategory">product category</label>
	<select name="productCategory" id="productCategory">
		<option value=""     >&mdash; your choice &mdash;</option>
		<?php
		$sql = "SELECT * FROM productCategory WHERE isActive='1' ORDER BY description";
		$res = mysql_query( $sql );
		while( $row = mysql_fetch_array( $res ) ){
			echo "<option value=\"" . $row['id'] . "\" >(# " . $row['shelfNumber'] . " | " . $row['colorOnMap'] . ") " . $row['description'] . "</option>\n";
		}
		?>
		</select><br />

	<label for="productCategory">product location (shelf)</label>
	<select name="productCategory" id="productCategory">
		<option value=""     >&mdash; your choice &mdash;</option>
		<?php
		$sql = "SELECT * FROM tbl_shelfs";
		$res = mysql_query( $sql );
		if( !$res ) echo mysql_error();
		while( $row = mysql_fetch_array( $res ) ){
			echo "<option value=\"" . $row['shelf_ID'] . "\" >#" . $row['shelf_ID'] . "</option>\n";
		}
		?>
		</select><br />

	<label for="slotInShelf">slot-no. in shelf</label>
	<select name="slotInShelf" id="slotInShelf">
		<option value=""     >&mdash; your choice &mdash;</option>
		<?php
			for($x=1; $x<=50; $x++){
			echo "<option value=\"" . $x . "\"># " . $x . "</option>\n";
			}
		?>
	</select><br />
	
	<label for="image">image</label>
	<select name="image" id="image">
		<option value=""     >&mdash; your choice &mdash;</option>
		<?php
		$sql = "SELECT * FROM productImages ORDER BY description";
		$res = mysql_query( $sql );
		while( $row = mysql_fetch_array( $res ) ){
			echo "<option value=\"" . $row['id'] . "\" >" . $row['description'] . " | " . $row['filesize'] . "kB</option>\n";
		}
		?>
		</select> <a href="_setup_addProductImage.php">add image</a> <small>(unsaved data will get lost!)</small><br />
	<label for="isActive">active?</label><input type="checkbox" name="isActive" id="isActive" value="1" checked="checked" /><br />
	<?php makeFormField( "text"    , "googleReviewSearchString"    , "search string for google reviews" )?>
	<input type="submit" name="send" value="SAVE" />
</form>


<table class="iTable">
	<tr>
		<th>ID</th>
		<th>int. name</th>
		<th>name</th>
		<th>type</th>
		<th>no.</th>
		<th>category</th>
		<th>code</th>
		<th>image</th>
		<th>active</th>
		<th>delete?</th>
		<th>last write access</th>
		<th>tools</th>
	</tr>
	<?php
		$sql = "SELECT * FROM product ORDER BY id DESC";
		$res = mysql_query( $sql );
		while( $row = mysql_fetch_array( $res ) ){
			echo "<tr";
			if( !empty( $lastId ) && $lastId == $row['id'] ) { echo " class=\"newItem\" "; }
			echo ">\n";
			echo "<td>" . $row['id'] . "</td>\n";
			echo "<td>" . $row['internalName'] . "</td>\n";
			echo "<td>" . $row['marketingName'] . "</td>\n";
			echo "<td>" . $row['productType'] . "</td>\n";
			echo "<td>" . $row['itemNumber'] . "</td>\n";
			echo "<td>" . $row['productCategory_id'] . "</td>\n";
			echo "<td>" . $row['quickAccessCode'] . "</td>\n";
			echo "<td><img src =\"getBinaryData.php?blobId=" . $row['productImages_id'] . "\" height=\"30\" /></td>\n";
			echo "<td>" . iconStatus( $row['isActive'] ) . "</td>\n";
			echo "<td>" . iconStatus( $row['isMarkedForDeletion'] ) . "</td>\n";
			echo "<td>" . $row['lastWriteAccess'] . "</td>\n";
			echo "<td></td>\n";
			echo "</tr>\n";
		}
	?>
	<tr class="moreInformation lastItem">
		<td colspan="12"><a href="#">to add new products use the form above</a></td>
	</tr>
</table>









<?php
/*
?>
<h1>add bin location</h1>
<form method="post" action="">
	<?php makeFormField( "text"    , "name"          , "title" )?>
	<label for="colorOnMap">color on guidance system</label>
	<select name="colorOnMap" id="colorOnMap">
		<option value=""     >&mdash; your choice &mdash;</option>
		<option value="BLUE" >blue</option>
		<option value="RED"  >red</option>
		<option value="GREEN">green</option>
	</select><br />
	<?php makeFormField( "text"    , "positionOnMap" , "bin location" )?>
	<?php makeFormField( "checkbox", "isActive"      , "active?" )?>
	<input type="submit" value="SAVE" />
</form>
<?php
*/
?>

<?php
	page_footer();
?>